//
//  OADViewLifecycleViewController.m
//  OASDK_Works
//
//  Created by ChenJie on 5/21/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "OADViewLifecycleViewController.h"
#import "OASDK.h"
#import "OADViewLifecycleViewModel.h"
#import "OADTitleHeader.h"

@interface OADViewLifecycleViewController ()

@property (nonatomic, strong) OADViewLifecycleViewModel *viewModel;
@property (nonatomic, strong) OADTitleHeader *header;
@property (nonatomic, strong) UIView *body;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation OADViewLifecycleViewController

#pragma mark - ViewController lifecycle

- (instancetype)init {
    self = [super init];
    if (self) {
        self.viewModel = [[OADViewLifecycleViewModel alloc] init];
    }
    return self;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    //
    [self buildTable];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = NSStringFromClass(self.class);
    
    //
    [self.view addSubview:self.header];
//    [self.view addSubview:self.body];
    [self.view addSubview:self.tableView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    //
    CGFloat topMark = OA_NAVIGATION_BAR_BOTTOM + 10;
//    CGFloat headerHeight = [OADTitleHeader heightWithViewWidth:self.view.oa_width
//                                                     viewModel:self.viewModel.headerViewModel];
    
    CGFloat headerHeight = 100;
    CGSize headerSize = CGSizeMake(self.view.oa_width, headerHeight);
    [OADTitleHeader layoutWithViewSize:headerSize viewModel:self.viewModel.headerViewModel];
    
    self.header.frame = CGRectMake(0, topMark, self.view.oa_width, headerHeight);
    topMark += headerHeight;
    
    //
    CGFloat tableViewHeight = self.view.oa_height - topMark;
    self.tableView.frame = CGRectMake(0, topMark, self.view.oa_width, tableViewHeight);
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - Public methods



#pragma mark - Private methods

- (void)buildTable {
    OATableConfig *tableConfig = self.tableView.oa_tableConfig;
    
    for (NSInteger i = 0; i < 10; i++) {
        [tableConfig addCellWithType:nil viewModel:@{
            @"title": [NSString stringWithFormat:@"Title: %ld", (long)i],
            @"content": [NSString stringWithFormat:@"Content: %ld", (long)i],
        }];
    }
    
}

#pragma mark - Event response methods



#pragma mark - Deletate methods



#pragma mark - Setter

- (OADTitleHeader *)header {
    if (!_header) {
        OADTitleHeader *header = [[OADTitleHeader alloc] init];
        header.viewModel = self.viewModel.headerViewModel;
        
        _header = header;
    }
    return _header;
}

OAGetView(body, ^(UIView *view){
    view.backgroundColor = OARandomColor();
})

- (void)setViewModel:(OADViewLifecycleViewModel *)viewModel {
    _viewModel = viewModel;
    
    
}

#pragma mark - Getter

OAGetTableView(tableView, ^(UITableView *tableView){
    
});

#pragma mark - Memory management

- (void)dealloc {
    OALogFunction
}

@end
